package com.maotai.dao;

import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class QiangGouDao{


    public List<Map<String,Object>> getAllZhanghaoLoginAndBuy2018(){

        Connection c = null;
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        try {
            Class.forName("com.mysql.jdbc.Driver");

         c = DriverManager.getConnection("jdbc:mysql://192.168.43.19:3306/mymaotai?user=root&password=123456&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false");

        Statement stmt = null;
        try {
            c.setAutoCommit(false);
            stmt = c.createStatement();
            String sql = "select web.code,web.pwd,web.auth,invo.invoicetext,addr.id as addressId from zhanghaoweb web "+
                    "	join zhanghaoaddress addr on web.code = addr.code "+
                    "	join zhanghaoinvoice invo on web.code = invo.code "+
                    "	limit 1	";
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                Map<String,Object> map = new HashMap<String,Object>();
                map.put("code",rs.getString("code"));
                map.put("pwd",rs.getString("pwd"));
                map.put("auth",rs.getString("auth"));
                map.put("invoicetext",rs.getString("invoicetext"));
                map.put("addressId",rs.getString("addressId"));

                list.add(map);
            }
            stmt.close();
            c.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
        return list;
    }

}